﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//util stuff
namespace gwBedrockUtil
{
    //common definition
    class gwCommon
    {
        #region constant variable
        //global value
        public const int gwInvalidIndex = -1;
        #endregion

        #region helper function
        /// <summary>
        /// bits to bytes
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public uint bits_to_bytes(uint x)
        {
            return (((x) + 7) >> 3);
        }
        /// <summary>
        /// bytes to bits
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public uint bytes_to_bits(uint x)
        {
            return ((x) << 3);
        }
        /// <summary>
        /// make argb value
        /// </summary>
        /// <param name="a"></param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public uint make_argb(byte a, byte r, byte g, byte b)
        {
            return ((uint)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)));
        }
        /// <summary>
        /// convet rgba to argb
        /// </summary>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <param name="a"></param>
        /// <returns></returns>
        public uint rgba_to_argb(byte r, byte g, byte b, byte a)
        {
            return make_argb(a,r,g,b);
        }
        /// <summary>
        /// make xrgb value
        /// </summary>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public uint make_xrgb(byte r, byte g, byte b)
        {
            return make_argb(0xff, r, g, b);
        }
        #endregion
    }
}
